﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Weazel.Gezel.Simulator.Reference.IpBlocks
{
	[IpBlockAttribute("weazelpongsync")]
	public class WeazelPongSync : AbstractIpBlock
	{
		private const int SyncCanWritePinNumber = 0;
		private const int SyncDoWritePinNumber = 1;
		private const int SyncPinNumber = 2;

		public WeazelPongSync(string name)
      : base(name)
    {      
    }

		public override void SetParameter(string _name)
		{
			// nothing
		}

		public override bool CheckTerminal(int n, string tname, IoDirection dir)
		{
			switch (n)
			{
				case 0:
					return (dir == AbstractIpBlock.IoDirection.Input && tname == "sync_out_can_write");
				case 1:
					return (dir == AbstractIpBlock.IoDirection.Input && tname == "sync_out_do_write");
				case 2:
					return (dir == AbstractIpBlock.IoDirection.Input && tname == "sync_out");

				default:
					throw new NotSupportedException("CheckTerminal() unknown 'n' value");
			}
		}

		public override void Run()
		{
			try
			{
				int canWrite = ioValues[SyncCanWritePinNumber].ToInt();
				// ioValues[SyncDoWritePinNumber].ToInt();
				// ioValues[SyncPinNumber].ToInt();

				System.Threading.Thread.Sleep(20);

				//Console.WriteLine("ball position ({0}, {1})", ballX, ballY);
			}
			catch (Exception e)
			{
				String message = e.GetType().ToString() + " " +
					e.Message + " trace: \n" + e.StackTrace;

				System.Windows.Forms.MessageBox.Show(message);
			}
		}
	}
}
